package cn.yunhe.songshan.ssm.controller;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import cn.yunhe.songshan.ssm.model.Result;

/**
 * 全局异常处理
 * 
 * @author YUNHE
 *
 */
@ControllerAdvice
public class GlobalException {

	@ExceptionHandler(NullPointerException.class)
	@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
	@ResponseBody
	public Result cs1(NullPointerException ex){
		System.out.println("111111");
		//ex.printStackTrace();
		System.out.println("222222");
		Result rs =new Result();
		rs.setRscode(4001);
		rs.setRsmsg("空指针异常");
		return rs;
	}
	

	@ExceptionHandler(Exception.class)
	public Result cs2(Exception ex){
		System.out.println("111111");
		//ex.printStackTrace();
		System.out.println("222222");
		Result rs =new Result();
		rs.setRscode(4000);
		rs.setRsmsg("异常");
		return rs;
	}

	
}
